<?php

namespace App\Jobs;

use App\Services\Square\FeedsService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;

/***
 * 
 * 信息流分发
 * php artisan queue:work --queue=FeedDispatch
 * 
 **/
class FeedDispatch implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $data;

    /**
     * Create a new job instance.
     *
     * $data['post_uuid'] = '132';
     * $data['member_uuid'] = '3333';
     * @return void
     */
    public function __construct($data)
    {
        //
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try{
            FeedsService::feedDispatchJob($this->data['feed_param'], $this->data['feed_row']);
        } catch (\Exception $exception) {
             $this->fail($exception);
        }
    }

    /**
     * 
     *  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'migo.laravel_failed_jobs' doesn't exist (SQL: insert into `laravel_failed_jobs` (`connection`, `queue`, `payload`, `exception`, `failed_at`) values (redis,
     **/
    public function fail($exception)
    {
        //
        Log::alert($exception->getMessage());   
    }
    
}


